<?php
@session_start();
$PurviewLevel=2;
$CheckChannelID=0;  
$PurviewLevel_Others="yingxiao_vpp_class";

require("../../inc/common.inc.php");
require_once("../Admin_ChkPurview.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link rel="stylesheet" href="../images/style.css" type="text/css">
</head>
<script>
function checkclass(){
	if (!CheckLength("name","栏目名称")){
		return false;
	}
	<?php if ($Purview!=1){?>
	if (!CheckSelect("name","所属分类'")){
		return false;
	}
	<?php }?>
}
</script>
<body>
<?php require("../mx_head.php");?>
<div class="right">
		<div class="height15"></div>
		<div class="xm2">
			<h1 class="fl">栏目管理</h1>
			<div class="clear"></div>
		</div>
		<div class="xm2_b">
		  <div class="t">
		    <table border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td><div class="an1"><a href="yx_vpp_class.php?action=add">添加栏目</a></div></td>
                <td><div class="an2"><a href="yx_vpp_class.php">栏目管理</a></div></td>
              </tr>
            </table>
		  </div>
		  <div class="height15"></div>
<?php
$action=trim($_REQUEST['action']);
if ($action=="saveadd"){
//新类，添加到数据库
  $fup=trim($_POST['fup']);
  $name=trim($_POST['name']);
  if ($Purview!=1 and intval($fup)==0){
  	  $fun->popmassage("您没有对此分类的管理权限，系统将自动返回！","","popback");
	  exit();
  }
  if (strpos("#**#$fiddbadmin2","|||$fup|||")<=0 and  $Purview!=1){
		$fun->popmassage("您没有对所选分类的管理权限","","popback");
		exit();
  }
  if ($name==""){
  	$fun->popmassage("您没有填写添加新栏目的名称，请重新输入！","","popback");
	exit();
  }
	if($fup){
		$rs=$db->getinfo("SELECT * FROM mx_vpp_articleclass WHERE fid='$fup' ");
		$class=$rs['class'];
		$db->excu("UPDATE mx_vpp_articleclass SET sons=sons+1 WHERE fid='$fup'");
		$type=0;
	}else{
		$type=1;	/*分类标志*/
		$class=0;
	}
	$classshowtype=intval($classshowtype);
	$classtype=intval($classtype);
	$jumpurl=$jumpurl;
	$class++;
    if ($orderid==""){$orderid=666;}
    if ($fup==""){$fup=0;}
	
	$fields=array(
		"name"           =>$name,
		"fup"            =>$fup,
		"class"          =>$class,
		"type"           =>$type,
		"classshowtype"  =>$classshowtype,
		"picurl"         =>$picurl,
		"picurl_b"       =>$picurl_b,
		"classtype"      =>$classtype,
		"list"           =>$orderid,
		"jumpurl"        =>$jumpurl,
		"keywords"       =>$keywords,
		"descrip"        =>$descrip,
	);
	$db->exe_insert("mx_vpp_articleclass",$fields);	
	
	mod_sort_class("mx_vpp_articleclass",0,0);		//更新class
	mod_sort_sons("mx_vpp_articleclass",0);			//更新sons

	jump2("创建成功","yx_vpp_class.php");
	exit();

}
elseif ($action=="saveedit"){
//保存修改设置
	//检查父栏目是否有问题
    if ($fid=="" || empty($fid)){
  	  $fun->popmassage("请选择要修改的栏目！","","popback");
	  exit();
    }
	
    if (strpos("#**#$fiddbadmin2","|||$fid|||")<=0){
		$fun->popmassage("您没有对所选分类的管理权限","","popback");
		exit();
    }
	check_fup("mx_vpp_articleclass",$fid,$fup);

	$rs_fid=$db->get_one("SELECT * FROM mx_vpp_articleclass WHERE fid='$fid'");

	if ($Purview!=1 and intval($rs_fid["fup"])==0){
  	  $fun->popmassage("您没有对此分类的管理权限，系统将自动返回！","","popback");
	  exit();
	}
    if ($orderid==""){$orderid=666;}
    if ($fup==""){$fup=0;}
	$classshowtype=$classshowtype;
	$classtype=$classtype;
	$jumpurl=$jumpurl;
	
	$fields=array(
		"fup"             =>$fup,
		"name"            =>$name,
		"classshowtype"   =>$classshowtype,
		"picurl"          =>$picurl,
		"picurl_b"        =>$picurl_b,
		"classtype"       =>$classtype,
		"list"            =>$orderid,
		"jumpurl"         =>$jumpurl,
		"keywords"        =>$keywords,
		"descrip"         =>$descrip,
	);

	if($rs_fid[fup]!=$fup)
	{
		$rs_fup=$db->getinfo("SELECT * FROM mx_vpp_articleclass WHERE fup='$fup' ");
		$newclass=$rs_fup['class']+1;
		$db->excu("UPDATE mx_vpp_articleclass SET sons=sons+1 WHERE fup='$fup' ");
		$db->excu("UPDATE mx_vpp_articleclass SET sons=sons-1 WHERE fup='$rs_fid[fup]' ");
		$fields["class"]=$newclass;
	}
	$db->exe_update("mx_vpp_articleclass",$fields," fid='$fid'");
	//修改栏目名称之后,文章的也要跟着修改
	if($rs_fid[name]!=$name)
	{
		$db->excu(" UPDATE mx_vpp_article SET fname='$name' WHERE fid='$fid' ");
	}
	
	
	mod_sort_class("mx_vpp_articleclass",0,0);		//更新class
	mod_sort_sons("mx_vpp_articleclass",0);			//更新sons
	jump2("修改成功","yx_vpp_class.php");
	exit();
}

elseif ($action=="delete"){
//删除分类
    if ($fid=="" || empty($fid)){
  	  $fun->popmassage("请选择要修改的栏目！","","popback");
	  exit();
    }
    if (strpos("#**#$fiddbadmin2","|||$fid|||")<=0){
		$fun->popmassage("您没有对所选分类的管理权限","","popback");
		exit();
    }
	$fup=$db->get_one("select fup from mx_vpp_articleclass where fid='$fid'");
	if ($Purview!=1 and intval($fup)==0){
  	  $fun->popmassage("您没有对此分类的管理权限，系统将自动返回！","","popback");
	  exit();
	}
	$db->excu(" DELETE FROM mx_vpp_articleclass WHERE fid='$fid' ");
	$db->excu(" DELETE FROM mx_vpp_article WHERE fid='$fid' ");

	mod_sort_class("mx_vpp_articleclass",0,0);		//更新class
	mod_sort_sons("mx_vpp_articleclass",0);			//更新sons

	jump2("删除成功","yx_vpp_class.php");
	exit();
}
elseif($action=="editlist")
{
  //批量修改排序

	foreach( $order AS $key=>$value){
    if (strpos("#**#$fiddbadmin2","|||$key|||")<=0){
		$fun->popmassage("您没有对所选分类的管理权限","","popback");
		exit();
    }
	$fup=$db->get_one("select fup from mx_vpp_articleclass where fid='$key'");
	if ($Purview!=1 and intval($fup)==0){
  	  $fun->popmassage("您没有对此分类的管理权限，系统将自动返回！","","popback");
	  exit();
	}
		$db->excu("UPDATE mx_vpp_articleclass SET list='$value' WHERE fid='$key' ");
	}
	mod_sort_class("mx_vpp_articleclass",0,0);		//更新class
	mod_sort_sons("mx_vpp_articleclass",0);			//更新sons

	jump2("修改成功","$FROMURL",1);
	exit();
}

elseif ($action=="editclass"){
    $fid=trim($_REQUEST['fid']);
    if ($fid=="" || empty($fid)){
  	  $fun->popmassage("非法访问，系统将自动返回！","","popback");
	  exit();
    }
    if (strpos("#**#$fiddbadmin2","|||$fid|||")<=0){
		$fun->popmassage("您没有对所选分类的管理权限","","popback");
		exit();
    }
	$rsdb=$db->get_one("SELECT * FROM mx_vpp_articleclass WHERE fid='$fid'");
	if ($Purview!=1 and intval($rsdb["fup"])==0){
  	  $fun->popmassage("您没有对此分类的管理权限，系统将自动返回！","","popback");
	  exit();
	}
	$sort_fid=$Guidedb->Select("mx_vpp_articleclass","fid",$fid,"prview","yx_vpp_class.php?action=editclass","",4);
	$sort_fup=$Guidedb->Select("mx_vpp_articleclass","fup",$rsdb[fup],"prview","","",3);
	$classtype[$rsdb["classtype"]]=" selected";
	$classshowtype[$rsdb["classshowtype"]]=" selected";
?>
<div class="n_div" style="width:100%;">
<table border="0" cellspacing="1" cellpadding="5" width="100%" class="table_southidc">
  <form name="form" method="post" action="yx_vpp_class.php?action=saveedit" enctype="multipart/form-data" onSubmit="return checkclass();">
    <tr align="center"> 
      <th colspan="2">栏目修改</th>
    </tr>
    <tr class="list"> 
      <td width="30%" align="right">当前栏目:</td>
      <td width="70%"><?php echo $sort_fid;?></td>
    </tr>
    <tr class="list"> 
      <td align="right">栏目名称:</td>
      <td><input type="text" name="name" value="<?php echo $rsdb[name];?>" /></td>
    </tr>
    <tr class="list"> 
      <td align="right">显示类型:</td>
      <td><select name="classshowtype">
	  <option value="0" <?php echo $classshowtype[0]?>>文字</option>
	  <option value="1" <?php echo $classshowtype[1]?>>图片</option>
	  </select>
	  </td>
    </tr>
    <tr class="list"> 
      <td align="right">所属分类:</td>
      <td><?php echo $sort_fup?></td>
    </tr>
    <tr class="list"> 
      <td align="right">分类小图:</td>
      <td>
	  <input class=mmcinb type='text' name='picurl' value='<?php echo $rsdb["picurl"]?>' id="picurl" size="40">&nbsp;<a href="javascript:show_uplode('upfile','articleclass','picurl')"><font color="#FF0000">点击上传图片</font></a></td>
    </tr>
    <tr class="list"> 
      <td align="right">分类大图:</td>
      <td>
	  <input class=mmcinb type='text' name='picurl_b' value='<?php echo $rsdb["picurl_b"]?>' id="picurl_b" size="40">&nbsp;<a href="javascript:show_uplode('upfile','articleclass','picurl_b')"><font color="#FF0000">点击上传图片</font></a></td>
    </tr>
    <tr class="list"> 
      <td align="right">栏目排序:</td>
      <td><input type=text name="orderid" size=20 value="<?php echo $rsdb["list"]?>"></td>
    </tr>
    <tr class="list"> 
      <td align="right">内容类型:</td>
      <td><select name="classtype">
	  <option value="0" <?php echo $classtype[0]?>>列表</option>
	  <option value="1" <?php echo $classtype[1]?>>图片列表</option>
	  <option value="4" <?php echo $classtype[4]?>>图片墙</option>
	  <option value="5" <?php echo $classtype[5]?>>图片墙二</option>
	  <option value="2" <?php echo $classtype[2]?>>单页</option>
	  <option value="3" <?php echo $classtype[3]?>>外链</option>
	  </select>	  </td>
    </tr>
    <tr class="list"> 
      <td align="right">外链地址:</td>
      <td><input type=text name="jumpurl" size=50 value="<?php echo trim($rsdb["jumpurl"])?>"><br />栏目选择外链此链接有效</td>
    </tr>
    <tr class="list"> 
      <td align="right">关 键 字:</td>
      <td><input type=text name="keywords" size=50 value="<?php echo trim($rsdb["keywords"])?>"></td>
    </tr>
    <tr class="list"> 
      <td align="right">栏目简介:</td>
      <td><input type=text name="descrip" size=50 value="<?php echo trim($rsdb["descrip"])?>"></td>
    </tr>
    <tr class="list" align="center"> 
      <td colspan="2" class="list"> <input type="submit" name="Submit" value="提交" class="button"></td>
    </tr>
  </form>
</table>
</div>
<?php
}
elseif ($action=="add"){
	$fup=intval($fup);
	if ($fup>0){
		$fupinfo=$db->getinfo("select * from mx_vpp_articleclass where fid='$fup'");
		if (!is_array($fupinfo)){
		  $fun->popmassage("请选择正确分类，系统将自动返回！","","popback");
		  exit();
		}
	}
?>
<div class="n_div" style="width:100%;">
<table width=100% cellspacing=1 cellpadding=5  class="table_southidc">
  <tr align="center"> 
    <th colspan="2">添加栏目</th>
  </tr>
  <?php 
  ?>
    <form name="form" method="post" action="yx_vpp_class.php?action=saveadd" enctype="multipart/form-data" onSubmit="return checkclass();">
    <tr class="list"> 
      <td width="35%" align="right">栏目名称:</td>
      <td width="65%"><input type=text name="name" size=20></td>
    </tr>
    <tr class="list"> 
      <td align="right">显示类型:</td>
      <td><select name="classtype">
	  <option value="0" <?php echo $classshowtype[0]?>>文字</option>
	  <option value="1" <?php echo $classshowtype[1]?>>图片</option>
	  </select>
	  </td>
    </tr>
    <tr class="list"> 
      <td align="right">所属分类:</td>
      <td><?php
		$sort_fup=$Guidedb->Select("mx_vpp_articleclass","fup",$fup,"prview","yx_vpp_class.php?action=add","",3);
		echo $sort_fup;
		 ?>(不选择将成为一级分类) </td>
    </tr>
    <tr class="list"> 
      <td align="right">分类小图:</td>
      <td>
	  <input class=mmcinb type='text' name='picurl' value='<?php echo $rsdb["picurl"]?>' id="picurl" size="40">&nbsp;<a href="javascript:show_uplode('upfile','articleclass','picurl')"><font color="#FF0000">点击上传图片</font></a></td>
    </tr>
    <tr class="list"> 
      <td align="right">分类大图:</td>
      <td>
	  <input class=mmcinb type='text' name='picurl_b' value='<?php echo $rsdb["picurl_b"]?>' id="picurl_b" size="40">&nbsp;<a href="javascript:show_uplode('upfile','articleclass','picurl_b')"><font color="#FF0000">点击上传图片</font></a></td>
    </tr>
    <tr class="list"> 
      <td align="right">栏目排序:</td>
      <td><input type=text name="orderid" size=20 value="666"></td>
    </tr>
    <tr class="list"> 
      <td align="right">内容目类型:</td>
      <td><select name="classtype">
	  <option value="0" <?php echo $classtype[0]?>>列表</option>
	  <option value="1" <?php echo $classtype[1]?>>图片列表</option>
	  <option value="4" <?php echo $classtype[4]?>>图片墙</option>
	  <option value="5" <?php echo $classtype[4]?>>图片墙二</option>
	  <option value="2" <?php echo $classtype[2]?>>单页</option>
	  <option value="3" <?php echo $classtype[3]?>>外链</option>
	  </select>	  </td>
    </tr>
    <tr class="list"> 
      <td align="right">外链地址:</td>
      <td><input type=text name="jumpurl" size=50 value=""><br />栏目选择外链此链接有效</td>
    </tr>
    <tr class="list"> 
      <td align="right">关 键 字:</td>
      <td><input type=text name="keywords" size=50></td>
    </tr>
    <tr class="list"> 
      <td align="right">栏目简介:</td>
      <td><input type=text name="descrip" size=50></td>
    </tr>
    <tr class="list"> 
      <td colspan="2" height="25" align="center"><input type=submit value="提 交" name="submit" class="button"></td>
    </tr>
    </form>
</table>
</div><?php  }
elseif ($action=="" || empty($action)){
	$fid=intval($fid);
	$sortdb=array();
	list_allsort($fid,"mx_vpp_articleclass","","prview");

	if($fid){
		$rsdb=$db->get_one(" SELECT * FROM mx_vpp_articleclass WHERE fid='$fid' ");
	}
?>
<form name="formlist" method="post" action="index.php?lfj=$lfj&action=editlist">
<table width=95% cellspacing=1 cellpadding=3  class="table_southidc">
  <tr class="list"> 
      <td height="30" align="left">注意:<font color="#FF0000">栏目排序的规则是,数值大的排在前面,只能是同一级的进行排序</td>
  </tr>
</table>
<div class="height15"></div>
<table width="100%" border="0" cellspacing="1" cellpadding="5" class="table_southidc">
  <tr align="center"> 
    <th width="10%">ID</th>
    <th>栏目名称</th>
    <th width="6%">排序</th>
    <th width="20%">设置</th>
    <th width="10%">删除</th>
  </tr>
<?php
foreach($sortdb AS $key=>$rs){?>
  <tr class="list" onMouseOver="this.className='list2'" onMouseOut="this.className='list'"> 
    <td align="center"><b><font color="#FF0000"><?php echo $rs[fid]?></font></b></td>
    <td><?php echo $rs[icon]?>【<?php echo $rs[name]?>】</td>
    <td align="center"> 
      <?php if ($Purview==1 or $rs[fup]!=0){?><input type='text' name='order[<?php echo $rs[fid]?>]' value='<?php echo $rs['list'] ?>' size='5'><?php }?></td>
    <td align="center"><?php if($rs["class"]<3){?>[<a href='?action=add&fup=<?php echo $rs[fid]?>'><font color=red>添加分类</font></a>]<?php }
	if ($Purview==1 or $rs[fup]!=0){?>&nbsp;&nbsp;[<a href='?action=editclass&fid=<?php echo $rs[fid]?>'><font color=red>修改</font></a>]<?php } ?></td>
	<td align="center"><?php if ($Purview==1 or $rs[fup]!=0){?><a href="?action=delete&fid=<?php echo $rs[fid] ?>" onClick="return confirm('你确实要删除吗?不可恢复');">删除</a><?php }?></td>
  </tr>
<?php }?>
</table>
</form>
<div class="height15"></div>
<div align="center"><input type="button" name="Submit2" value="修改栏目排序" onClick="postlist('list')" class="button2">
<SCRIPT LANGUAGE="JavaScript">
function postlist(t){
	if(t=='list'){
		document.formlist.action="yx_vpp_class.php?action=editlist";
	}
	document.formlist.submit();
}
function CheckAll(va){
	form=document.formlist
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if(va=='all'){
			e.checked = true;
		}else{
			e.checked == true ? e.checked = false : e.checked = true;
		}
	}
}
</SCRIPT>
		  </div>
<?php
}?>
		  <div class="height15"></div>
		</div>
</div>
<?php 
require("../mx_foot.php");
?>
</body>
</html>
